package LeetcodeTest_forty_three;

//141. 环形链表
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class hasCycle
{
    public static void main(String[] args)
    {
        ListNode head=null;
        head=new ListNode(3);
        ListNode p1=head;
        ListNode p2=new ListNode(2);
        p1.next=p2;
        p2=new ListNode(0);
        p1=p1.next;
        p1.next=p2;
        p2=new ListNode(4);
        p1=p1.next;
        p1.next=p2;
        p1=p1.next;
        p1.next=head.next;
        System.out.println(solution.hasCycle(head));
    }
}
class solution
{
    public static boolean hasCycle(ListNode head)
    {
        Map<Integer,ListNode> map=new HashMap<Integer, ListNode>();
        int index1,index2;
        index1=0;
        ListNode p=head;
        while (p.next!=null)
        {
            if(!map.containsValue(p))
            {
                map.put(index1, p);
                index1++;
            }
            else
            {
                return false;
            }
            p=p.next;
        }
        index2=-1;
        return true;
    }

}
class ListNode
{
    int val;
    ListNode next;
    ListNode(int x) { val = x; }
}